package com.face.dao;

import com.face.common.Page;
import com.face.entity.Visit;
import com.face.mapper.VisitMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class VisitDao {
    @Autowired
    private VisitMapper visitMapper;

    public Page<Map<String, Object>> getVisitCountList(String shopId, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<Map<String, Object>> list = visitMapper.getVisitCountList(shopId);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
        return new Page<>(pageInfo.getTotal(), pageInfo.getList());
    }

    public Page<Map<String, Object>> getVisitCountList(String shopId, Integer page, Integer limit, String start, String end) {
        PageHelper.startPage(page, limit);
        List<Map<String, Object>> list = visitMapper.getVisitCounts(shopId, start, end);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
        return new Page<>(pageInfo.getTotal(), pageInfo.getList());
    }

    public Page<Visit> findByUserId(String shopId, String userId, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<Visit> list = visitMapper.findByUserId(shopId, userId);
        PageInfo<Visit> pageInfo = new PageInfo<>(list);
        return new Page<>(pageInfo.getTotal(), pageInfo.getList());
    }

    public Page<Visit> findByUserId(String shopId, String userId, Integer page, Integer limit, String start, String end) {
        PageHelper.startPage(page, limit);
        List<Visit> list = visitMapper.findByUserIdAndTime(shopId, userId, start, end);
        PageInfo<Visit> pageInfo = new PageInfo<>(list);
        return new Page<>(pageInfo.getTotal(), pageInfo.getList());
    }

    public Map<String, Object> findForWechatToRemark(String userId) {
        return visitMapper.findForWechatToRemark(userId);
    }

    public List<Map<String, Object>> statByDay(String shopId, String start, String end) {
        return visitMapper.statByDay(shopId, start, end);
    }

    public List<Map<String, Object>> statByMonth(String shopId, String start, String end) {
        return visitMapper.statByMonth(shopId, start, end);
    }
}
